package cn.jsc.org.data;

import cn.jsc.org.BaseTest;
import cn.jsc.pet.domain.Pet;
import cn.jsc.pet.domain.PetDetail;
import cn.jsc.pet.mapper.PetDetailMapper;
import cn.jsc.pet.mapper.PetMapper;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.BigDecimal;

/**
 * 伪造Pet数据
 */
public class CreatePet extends BaseTest {

    @Autowired
    private PetMapper petMapper;

    @Autowired
    private PetDetailMapper petDetailMapper;

    @Test
    public void test1() throws Exception{
        Pet pet = petMapper.loadById(206L);
        PetDetail petDetail = petDetailMapper.loadByPetId(pet.getId());

        for(int i = 0;i<100;i++){
            if(i%2==0){
                pet.setId(null);//自增长
                petDetail.setId(null);
                pet.setName("小猪佩奇" + i);
                pet.setState(1);
                pet.setSaleprice(new BigDecimal(i*10));
                pet.setCostprice(new BigDecimal(i*5));

                petMapper.save(pet);
                petDetail.setPet_id(pet.getId());
                petDetailMapper.save(petDetail);
            }else{
                pet.setId(null);//自增长
                petDetail.setId(null);
                pet.setName("野猪乔治" + i);
                pet.setState(0);
                pet.setSaleprice(new BigDecimal(i*10));
                pet.setCostprice(new BigDecimal(i*5));

                petMapper.save(pet);
                petDetail.setPet_id(pet.getId());
                petDetailMapper.save(petDetail);
            }
        }
    }
}
